<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Stock_model extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    /*     * *************************************************************************
     * Accesseurs
     * ************************************************************************ */

    public function get($ARTICLE_ID) {
        $sql = "SELECT SUM(STOCK_QUANTITE) AS STOCK
                FROM STOCK
                WHERE ARTICLE_ID=" . $ARTICLE_ID;

        $query = $this->db->query($sql);
        $data = array();
        
        if ($query->num_rows() > 0) {
            $data=$query->result();
            $data = $data[0];
            if($data->STOCK == null) {
                $data->STOCK = 0;
            }
        }

        return $data;
    }

    /*     * *************************************************************************
     * Méthodes d'enregistrement
     * ************************************************************************ */
/*
    public function addstock($ARTICLE_ID, $NB_STOCK) {
        $this->db->set('SOCIETE_NOM', $SOCIETE_NOM)
                ->insert('societe');

        $SOCIETE_ID = $this->db->insert_id();

        $this->db->set('SOCIETE_ID', $SOCIETE_ID)
                ->insert('fournisseur');
    }

    public function update($SOCIETE_ID, $SOCIETE_NOM) {
        $data = array(
            'SOCIETE_NOM' => $SOCIETE_NOM
        );
        $this->db->where('SOCIETE_ID', $SOCIETE_ID)
                ->update('societe', $data);
    }

    public function Delete($SOCIETE_ID) {
        $this->db->where('SOCIETE_ID', $SOCIETE_ID)
                ->delete('fournisseur');
    }*/

}

?>